/**
 * 
 */
package com.thor.palmmall.rest.tenant.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.OperateInfoToBeanConverter;
import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.common.OperateInfoConverter;
import com.thor.palmmall.rest.tenant.ATenant;
import com.thor.palmmall.spi.common.SOperateInfoConverter;
import com.thor.palmmall.spi.tenant.STenant;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class STenantConverter implements Converter<ATenant, STenant> {

  public static STenantConverter getInstance() {
    if (instance == null)
      instance = new STenantConverter();
    return instance;
  }

  private static STenantConverter instance;

  private STenantConverter() {
  }

  @Override
  public STenant convert(ATenant source) {
    if (source == null) {
      return null;
    }
    STenant target = new STenant();
    target.setAddress(source.getAddress());
    target.setBankAccount(source.getBankAccount());
    target.setBankName(source.getBankName());
    target.setBrands(new ArrayList<UCN>());
    target.getBrands().addAll(source.getBrands());
    target.setCode(source.getCode());
    target.setContactInfos(
        ConverterUtil.convert(source.getContactInfos(), SContactInfosConverter.getInstance()));
    target.setContracts(new ArrayList<UCN>());
    target.getContracts().addAll(source.getContracts());
    target.setLastModifyInfo(SOperateInfoConverter.getInstance()
    		.convert(OperateInfoToBeanConverter.getInstance().convert(source.getLastModifyInfo())));
    target.setCreateInfo(SOperateInfoConverter.getInstance()
    		.convert(OperateInfoToBeanConverter.getInstance().convert(source.getCreateInfo())));
    target.setFax(source.getFax());
    target.setForeignName(source.getForeignName());
    target.setIntroduction(source.getIntroduction());
    target.setLegalName(source.getLegalName());
    target.setLegalPersion(source.getLegalPersion());
    target.setLogos(ConverterUtil.convert(source.getLogos(), SLogosConverter.getInstance()));
    target.setName(source.getName());
    target.setPermGroups(new ArrayList<UCN>());
    target.getPermGroups().addAll(source.getPermGroups());
    target.setPhone(source.getPhone());
    target.setQq(source.getQq());
    target.setRegisterAddress(source.getRegisterAddress());
    target.setRegisterPhone(source.getRegisterPhone());
    target.setRemark(source.getRemark());
    target.setShortForeignName(source.getShortForeignName());
    target.setShortName(source.getShortName());
    target.setState(source.getState());
    target.setTag(source.getTag());
    target.setTaxCode(source.getTaxCode());
    target.setUuid(source.getUuid());
    target.setVersion(source.getVersion());
    target.setVersionTime(source.getVersionTime());
    target.setWeb(source.getWeb());
    return target;

  }

}
